﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class WebForm_ManageRoad_ManageRoadItem : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string RoadID = Request.QueryString["RoadID"];
        SqlDataSource2.SelectParameters["RoadID"].DefaultValue = RoadID;
        SqlDataSource2.InsertParameters["RoadID"].DefaultValue = RoadID;
        dsRole1.InsertParameters["RoadID"].DefaultValue = RoadID;
        dsRole1.SelectParameters["RoadID"].DefaultValue = RoadID;
        dsRole1.UpdateParameters["RoadID"].DefaultValue = RoadID;
        dsRole1.DeleteParameters["RoadID"].DefaultValue = RoadID;

        dsRole2.InsertParameters["RoadID"].DefaultValue = RoadID;
        dsRole2.SelectParameters["RoadID"].DefaultValue = RoadID;
        dsRole2.UpdateParameters["RoadID"].DefaultValue = RoadID;
        dsRole2.DeleteParameters["RoadID"].DefaultValue = RoadID;      
    }
    #region "FormView事件"
    protected void fv_DataBound(object sender, EventArgs e)
    {
        Label lblRoadName = (Label)fv.FindControl("lblRoadName");
        lblRoadName.Text = MyObj.GetRoadName(Request.QueryString["RoadID"]);
    }
    #endregion

    #region "GridView事件"
    protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)   
        {
            Label lblNO = (Label)e.Row.FindControl("lblNO");
            lblNO.Text = (gv.PageIndex * gv.PageSize + e.Row.RowIndex + 1).ToString();
        }   
    }
    #endregion

    #region "fvRole1事件"
    protected void fvRole1_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        dsRole1.InsertParameters["OrganizationID"].DefaultValue = ((DropDownList)fvRole1.FindControl("ddlOrganizationName")).SelectedValue;
    }
    #endregion

    #region "gvRole1事件"
    protected void gvRole1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblNO = (Label)e.Row.FindControl("lblNO");
            lblNO.Text = (gvRole1.PageIndex * gvRole1.PageSize + e.Row.RowIndex + 1).ToString();
            DropDownList ddlItem = (DropDownList)e.Row.FindControl("ddlOrganizationName");
            if (ddlItem != null)
            {
                ddlItem.SelectedIndex = ddlItem.Items.IndexOf(ddlItem.Items.FindByValue(((HiddenField)e.Row.FindControl("hideOrganizationID")).Value));
            }
        }
    }

    protected void gvRole1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        dsRole1.UpdateParameters["New_OrganizationID"].DefaultValue = ((DropDownList)gvRole1.Rows[e.RowIndex].FindControl("ddlOrganizationName")).SelectedValue;
    }
    #endregion

    #region "fvRole2事件"
    protected void fvRole2_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        dsRole2.InsertParameters["OrganizationID"].DefaultValue = ((DropDownList)fvRole2.FindControl("ddlOrganizationName")).SelectedValue;
    }
    #endregion

    #region "gvRole2事件"
    protected void gvRole2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblNO = (Label)e.Row.FindControl("lblNO");
            lblNO.Text = (gvRole2.PageIndex * gvRole2.PageSize + e.Row.RowIndex + 1).ToString();
            DropDownList ddlItem = (DropDownList)e.Row.FindControl("ddlOrganizationName");
            if (ddlItem != null)
            {
                ddlItem.SelectedIndex = ddlItem.Items.IndexOf(ddlItem.Items.FindByValue(((HiddenField)e.Row.FindControl("hideOrganizationID")).Value));
            }
        }
    }

    protected void gvRole2_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        dsRole2.UpdateParameters["New_OrganizationID"].DefaultValue = ((DropDownList)gvRole2.Rows[e.RowIndex].FindControl("ddlOrganizationName")).SelectedValue;
    }
    #endregion

}
